package com.gxan.service.impl;

import com.gxan.common.R;
import com.gxan.dao.UserDao;
import com.gxan.dao.impl.UserDaoImpl;
import com.gxan.pojo.SysUser;
import com.gxan.service.UserService;

import java.sql.SQLException;

public class UserServiceImpl implements UserService {
    //创建Dao实例
    private UserDao userDao = new UserDaoImpl();
    @Override
    public R login(String username, Integer password) {
        //创建R对象
        R r = new R();        //调用dao去数据库查询
        try {
            //对password加密
//            String newpwd = MD5Utils.encrypt(password);
            SysUser user = userDao.findUserByUsernameAndPwd(username, password);
            System.out.println(user);
            if(user!=null){
                //成功
                r.setCode(200);
                r.setMsg("登录成功");
                r.setData(user);
            }else{
                //失败
                r.setCode(500);
                r.setMsg("用户名或密码有误");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(501);
            r.setMsg("a");
        }
        return r;
    }
}
